/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.admin.dto.ElevatorPlanUserDTO;
import org.springblade.modules.admin.dto.ElevatorStopPlanSimpleDTO;
import org.springblade.modules.admin.dto.PerformanceDTO;
import org.springblade.modules.admin.dto.PlanUserAllDTO;
import org.springblade.modules.admin.dto.feishu.ElevatorMaintainCostPlanListDTO;
import org.springblade.modules.admin.dto.feishu.FeiShuUserDeptElevatorWxPlanDTO;
import org.springblade.modules.admin.dto.feishu.UserPerformanceMonthPlanListDTO;
import org.springblade.modules.admin.dto.plan.BatchModifyPlanUserDTO;
import org.springblade.modules.admin.dto.plan.PlanSearchDTO;
import org.springblade.modules.admin.dto.plan.score.PlanScoreSearchDTO;
import org.springblade.modules.admin.dto.sugar.BiWxPlanListDTO;
import org.springblade.modules.admin.dto.sugar.ElevatorByCollectListDTO;
import org.springblade.modules.admin.dto.sugar.SugarSearchDTO;
import org.springblade.modules.admin.dto.tlw.TlwPlanQueryDTO;
import org.springblade.modules.admin.entity.*;
import org.springblade.modules.admin.vo.*;
import org.springblade.modules.admin.vo.feishu.LarkRepairVO;
import org.springblade.modules.admin.vo.image.by.ByPlanImageSimpleListVO;
import org.springblade.modules.admin.vo.openapi.SidaMaintainPlanVO;
import org.springblade.modules.admin.vo.plan.*;
import org.springblade.modules.admin.vo.plan.store.PlanScoreListVo;
import org.springblade.modules.admin.vo.sugar.ElevatorDetailScreenVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkRescueCountSourceVO;
import org.springblade.modules.admin.vo.task.DeptMaintainPlanVO;
import org.springblade.modules.admin.vo.tlw.TlwByPlanVO;
import org.springblade.modules.system.entity.User;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * 维保任务表 Mapper 接口
 *
 * @author ysq
 * @since 2022-03-09
 */
public interface MaintainPlanContentMapper extends BaseMapper<MaintainPlanContent> {

	/**
	 * 自定义分页
	 *
	 * @param page
	 * @param maintainPlanContent
	 * @return
	 */
	List<MaintainPlanContentVO> selectMaintainPlanContentPage(IPage page, MaintainPlanContentVO maintainPlanContent);

	/**
	 * 查询占坑周期规则
	 * @param taskPlanId
	 * @param tenantId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
    MaintainTaskPlanTemplate findOccupyRule(@Param("taskPlanId") Long taskPlanId, @Param("tenantId") String tenantId);

	/**
	 * 查询任务计划模板（排除占坑模板）
	 * @param taskPlanId
	 * @param occupyId 排除占坑模板id
	 * @param tenantId
	 * @return
	 */
	@InterceptorIgnore(tenantLine="on")
	LinkedList<MaintainTaskPlanTemplate> findTaskPlanIgnoreOccupyPlan(@Param("taskPlanId") Long taskPlanId, @Param("occupyId") Long occupyId, @Param("tenantId") String tenantId);

	/**
	 * 根据给定年份查计划
	 * @param elevatorIds
	 * @param month
	 * @param typeStatus
	 * @param tenantId
	 * @return
	 */
	@InterceptorIgnore(tenantLine="on")
	List<MaintainPlanContentVO> getMaintainPlans(@Param("elevatorIds") List<Long> elevatorIds, @Param("month") Integer month, @Param("typeStatus") Integer typeStatus, @Param("tenantId") String tenantId);

	/**
	 * 根据部门id获取保养计划
	 * @param deptId
	 * @param yearMonth
	 * @return
	 */
	@InterceptorIgnore(tenantLine="on")
	List<DeptMaintainPlanVO> getDeptMaintainPlan(@Param("deptId") Long deptId, @Param("yearMonth") String yearMonth);

	/**
	 * 根据taskPlanId获取任务计划
	 * @param taskPlanId
	 * @param tenantId
	 * @return
	 */
	@InterceptorIgnore(tenantLine="on")
	MaintainTaskPlan getTaskPlanById(@Param("taskPlanId") Long taskPlanId, @Param("tenantId") String tenantId);

	/**
	 * 获取工单业绩数据
	 * @param performanceDTO 查询条件
	 * @return 数据集
	 */
	List<PerformanceVo> performanceData(@Param("performanceDTO") PerformanceDTO performanceDTO);

	/**
	 * 获取统计人员list
	 * @param page 分页信息
	 * @param performanceDTO 查询条件
	 * @return 数据集
	 */
	IPage<PerformanceVo> performanceUserData(IPage<PerformanceVo> page,@Param("performanceDTO") PerformanceDTO performanceDTO);

	/**
	 * 维保任务列表
	 * @version v2
	 * @param planSearchDTO 查询条件
	 * @return 数据集
	 */
	List<PlanResultVo> getV2Page(IPage page, @Param("planSearchDTO") PlanSearchDTOV2 planSearchDTO);


	/**
	 * 获取作业记录详情
	 *
	 * @param planId 任务id
	 * @return 数据集
	 */
	PlanContentWorkDetailCommonVo workDetail(@Param("planId") Long planId);

	/**
	 * 获取保养列表
	 * @param page 分页
	 * @param planSearchDTO 查询条件
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
    List <PlanListVo> planList(IPage<PlanListVo> page, @Param("planSearchDTO") PlanSearchDTO planSearchDTO);

	/**
	 * 获取维修列表
	 * @param planSearchDTO 查询参数
	 * @return 数据集
	 */
	List <PlanListVo> malfunctionList(IPage<PlanListVo> page, @Param("planSearchDTO")PlanSearchDTO planSearchDTO);

	LastPlanVO selectElevatorLastPlan(@Param("elevatorId") Long elevatorId,@Param("planId") Long planId);

	List<LastPlanVO> selectElevatorLastPlans(@Param("elevatorIds") List<Long> elevatorIds,@Param("planIds") List<Long> planIds);

	String getPlanTemplateName(@Param("planId") Long planId);

	List<PlanTemplateDescVO> getPlanTemplateNames(@Param("planIds") List<Long> planIds);

	@InterceptorIgnore(tenantLine = "on")
	ElevatorSimpleInfoVO getElevatorSimpleInfo(@Param("planId") Long planId);

	@InterceptorIgnore(tenantLine = "on")
    List<MaintainPlanContent> listPlanForCount(@Param("typeStatus") Integer typeStatus,@Param("startTime") String startTime,@Param("endTime") String endTime);

	@InterceptorIgnore(tenantLine = "on")
	List<MaintainPlanContent> listWxPlanForCount(@Param("typeStatus") String typeStatus);

    SugarCheckPlanStatusVO getSugarCheckPlanStatus(@Param("elevatorIds") List<Long> elevatorIds);

	List<SugarCheckPlanStatusVO> getSugarCheckPlanHalfYear(@Param("startDate") String startDate,@Param("endDate") String endDate);

	SugarCheckPlanDeptRankingsVO getSugarCheckPlanDeptRankings(@Param("deptId") Long deptId,@Param("startDate") String startDate,@Param("endDate") String endDate);

	/**
	 * 查询{interval}个月之内的维修列表
	 * @param interval
	 * @param unit 间隔单位 0-日，1-月
	 * @return
	 */
	List<MaintainPlanContentVO> selectMalfunctionListInMonth(@Param("interval") Integer interval, @Param("unit") Integer unit);

	/**
	 * 查询维修列表
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	List<MaintainPlanContentVO> selectMalfunctionList(@Param("startTime") String startTime, @Param("endTime") String endTime);

	/**
	 * 查询某个时间段内的维修列表
	 * @param beginDate 开始时间
	 * @param endDate 结束时间
	 * @return
	 */
	List<MaintainPlanContentVO> selectMalfunctionListByDate(@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);

	/**
	 * 查询某个时间段内的维修列表
	 * @param beginDate 开始时间
	 * @param endDate 结束时间
	 * @return
	 */
	List<MaintainPlanContentExtVO> selectMalfunctionExtListByDate(@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);

	/**
	 * 查询{interval}月之内的有效梯
	 * @param interval
	 * @param unit 间隔单位 0-日，1-月
	 * @return
	 */
	List<ElevatorEffectedVO> selectElevatorEffectedListInMonth(@Param("interval") Integer interval, @Param("unit") Integer unit);

	/**
	 * 查询有效梯
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	List<ElevatorEffectedVO> selectElevatorEffectedList(@Param("startTime") String startTime, @Param("endTime") String endTime);

	/**
	 * 查询某个时间段内内的有效梯
	 * @param beginDate 开始时间
	 * @param endDate 结束时间
	 * @return
	 */
	List<ElevatorEffectedVO> selectElevatorEffectedListByDate(@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);

	/**
	 * 查询1个月之内的保养统计
	 * @return
	 */
	List<MaintainPlanContentVO> selectMaintainListByOneMonth();

	/**
	 * 大屏-电梯情况统计板块
	 * @return
	 */
	ElevatorDetailScreenVO getElevatorDetailScreen();

	/**
	 * 获取所有工单数据,不区分租户，用来初始化数据
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
    List<MaintainPlanContent> getList();

	Map<String, Object> selectPlanSimpleDetailByElevator(@Param("elevatorId") Long elevatorId,@Param("planDate") Date planDate);

	/**
	 * 根据电梯id 获取最近保养工单的维保人员信息
	 * @param elevatorIds 电梯ids
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<User> getUserListByElevatorIds(@Param("elevatorIds") List<Long> elevatorIds);

	List<Map<String, Object>> estateSugarCheckPlanTop(String tenantId);

	List<MaintainPlanContent> estateSugarCheckPlanFinishStatus(@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("elevatorIds") List<Long> elevatorIds);

	/**
	 * 获取工单明细的其它时间
	 * @param planId 工单id
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
    PlanOtherInfoVo getPlanOtherInfo(@Param("planId") Long planId,@Param("tenantId") String tenantId);

	/**
	 * 根据用户id查询未来保养排期计划
	 * @param userId
	 * @return
	 */
	List<FutureMaintainPlanVO> selectFutureMaintainPlanByUserId(@Param("userId") Long userId);

	/**
	 * 配件审批统计
	 * @param userId
	 * @return
	 */
	List<PlanApproveUserVO> partApproveStatistical(@Param("userId") Long userId);

	/**
	 * 救援工单详情列表
	 * @param elevatorId
	 * @return
	 */
    List<RescueDetailVO> rescueDetailListByElevatorId(@Param("buildingId") Long buildingId, @Param("elevatorId") Long elevatorId);

    List<MaintainPlanContentUser> selectDimissionUserPlan(Long userId);

	/**
	 * 获取工单初始化数据
	 * @return 数据集
	 */
	List<PlanInitVo> getPlanListInitData();

    List<TlwByPlanVO> tlwByPlanPage(@Param("queryDTO") TlwPlanQueryDTO queryDTO, IPage<TlwByPlanVO> page);

	List<TlwByPlanVO> tlwByPlanList(@Param("queryDTO") TlwPlanQueryDTO queryDTO);

	TlwByPlanVO tlwByPlanDetail(@Param("planId") Long planId);

	/**
	 * 统计正在救援的工单数
	 * @param elevatorId
	 * @return
	 */
	int selectRescuingByElevatorIdCounts(@Param("elevatorId") Long elevatorId);

	/**
	 * 获取正在维修列表
	 * @param elevatorId
	 * @return
	 */
	List<TlwMalfunctioningListVO> selectMalfunctioningByElevatorIdList(@Param("elevatorId") Long elevatorId);

	/**
	 * 梯联网-维修详情
	 * @param tlwJoinId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	TlwMalfunctionDetailVO tlwMalfunctionDetail(@Param("tlwJoinId") String tlwJoinId);

	/**
	 * 救援大屏个人详情工单统计
	 * @param userIds
	 * @return
	 */
	List<MaintainPlanContent> screenUserPlanStatisticsList(@Param("userIds") List<Long> userIds);

	/**
	 * 获取工单（忽略租户）
	 * @param planId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	MaintainPlanContent getMaintainPlanById(Long planId);

	/**
	 * 电梯工单任务状态
	 * @param deviceIds
	 * @return
	 */
    List<ElevatorTaskStatusVO> getElevatorTaskStatusList(@Param("deviceIds") List<String> deviceIds);

	/**
	 * 梯联网单体统计数据
	 * @param deviceId
	 * @return
	 */
	List<MaintainPlanContentVO> getTlwElevatorStatistics(@Param("deviceId") String deviceId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

	/**
	 * 新维修大屏 规定时间内电梯报障数
	 * @param beginTimeDate 开始时间
	 * @param endTimeDate 结束时间
	 * @param elevatorIds
	 * @return 数量
	 */
	Integer getRepairElevatorCount(@Param("beginTimeDate") Date beginTimeDate,@Param("endTimeDate") Date endTimeDate,@Param("elevatorIds") List<Long> elevatorIds);

	/**
	 * 新维修大屏 规定时间内 重复故障梯数
	 * @param beginTimeDate 开始时间
	 * @param endTimeDate 结束时间
	 * @param elevatorIds
	 * @return 数量
	 */
	Integer getVeryMuchProblemElevatorCount(@Param("beginTimeDate") Date beginTimeDate,@Param("endTimeDate") Date endTimeDate,@Param("elevatorIds") List<Long> elevatorIds);

	/**
	 * 临时数据
	 * @param beginTimeDate 开始时间
	 * @param endTimeDate 结束时间
	 * @return map
	 */
	NewRepairScreenTempVO getPlanSourceMap(Date beginTimeDate, Date endTimeDate);

	/**
	 * 2023-11-03 故障率与数据大屏同步
	 * @param beginTimeDate 开始时间
	 * @param endTimeDate 结束时间
	 * @return 与强哥一样的格式
	 */
	List<MaintainPlanContentVO> selectMalfunctionListInMonthPlus(Date beginTimeDate, Date endTimeDate);

	/**
	 * 2023-11-03 故障率与数据大屏同步
	 * @param beginTimeDate 开始时间
	 * @param endTimeDate 结束时间
	 * @return 与强哥一样的格式
	 */
	List<ElevatorEffectedVO> selectElevatorEffectedListInMonthPlus(Date beginTimeDate, Date endTimeDate);

	List<MaintainPlanContent> listWxPlan(@Param("beginTimeDate") Date beginTimeDate,@Param("endTimeDate") Date endTimeDate);

	List<ByPlanImageSimpleListVO> selectByAllImage(@Param("startDate") String startDate,@Param("endDate") String endDate);
	/**
	 * 保养排期日历数据
	 * @param calendarDate
	 * @return
	 */
    List<MaintainCalendarDataVO> maintainPlanCalendarList(@Param("calendarDate") String calendarDate);
	/**
	 * 查询保养排期单日待开始工单
	 * @param iPage
	 * @param planSearchDTO
	 * @return
	 */
    List<PlanListVo> selectPlanOnlyDayListDisable(IPage<PlanListVo> iPage,@Param("planSearchDTO") PlanSearchDTO planSearchDTO);

	List<PlanListVo> selectPlanOnlyDayListProcessedAndCommit(IPage<PlanListVo> iPage,@Param("planSearchDTO") PlanSearchDTO planSearchDTO);

	List<PlanListVo> selectPlanOnlyDayListFinish(IPage<PlanListVo> iPage,@Param("planSearchDTO") PlanSearchDTO planSearchDTO);

	/**
	 * 保养工单基础信息
	 * @param planIds
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<MaintainPlanBaseInfoVO> getMaintainPlanBaseInfosByPlanIds(@Param("planIds") List<Long> planIds);

	@InterceptorIgnore(tenantLine = "on")
	List<PlanListVo> selectByPlanList(IPage<PlanListVo> iPage,@Param("planSearchDTO") PlanSearchDTO planSearchDTO);



	/**
	 * 获取抽检的工单列表
	 * @param page 分页信息
	 * @param planScoreSearchDTO 查询条件
	 * @return 数据集
	 */
    List<PlanScoreListVo> getPlanScoreList(IPage<PlanScoreListVo> page,@Param("planScoreSearchDTO") PlanScoreSearchDTO planScoreSearchDTO);


	/**
	 * 获取评分抽检的列表的所有工单
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @param typeStatus 工单类型
	 * @return 数据集
	 */
	List<MaintainPlanContentExt> getPlanScoreMonthList(@Param("beginTime") Date beginTime,@Param("endTime") Date endTime,@Param("typeStatus") Integer typeStatus);

	@InterceptorIgnore(tenantLine = "on")
	ElevatorSimpleInfoVO selectPlanElevatorInfo(Long planId);


	/**
	 * 获取维修的评分列表
	 * @param page 分页信息
	 * @param planScoreSearchDTO 查询条件
	 * @return 数据集
	 */
    List<PlanScoreListVo> getPlanScoreListWx(IPage<PlanScoreListVo> page, PlanScoreSearchDTO planScoreSearchDTO);
	List<Long> getFromPlanIdByOwnId(Long ownId);

	List<PlanSourceVO> getPlanSourceMessagesByIds(List<Long> fromPlanIdByOwnId);

	List<String> getExecuteUserNamesByPlanId(Long sourcePlanId);

    List<MaintainPlanContent> listEmptyPlanSource();

	List<PlanListVo> selectByPlanListLark(@Param("planSearchDTO") PlanSearchDTO planSearchDTO);

	/**
	 * 飞书维修工单列表
	 * @param planId 工单id
	 * @return 数据集
	 */
	List<LarkRepairVO> getLarkRepairVOListByPlanId(Long planId);

	/**
	 * 根据电梯id及时间区间查询重复故障次数
	 * @param elevatorId 电梯id
	 * @param beginTime 开始时间
	 * @param endTime 	结束时间
	 * @return 重复故障次数
	 */
	int troubleCount(Long elevatorId, Date beginTime, Date endTime);

    ElevatorStopPlanSimpleDTO selectElevatorStopPlanSimple(Long planId);

	List<PlanListVo> selectByPlanListLarkTemp(@Param("planSearchDTO") PlanSearchDTO planSearchDTO);

	/**
	 * 根据计划id获取电梯信息
	 * @param planId 计划id
	 * @return 电梯信息
	 */
	ElevatorRescueRobotSimpleVO getElevatorSimpleInfoByPlanId(Long planId);

    List<ElevatorEffectedVO> selectElevatorEffectedListByEndDate(String endTime);

	List<SidaMaintainPlanVO> getMaintainPlanListByTenantIdAndTime(String tenantId, Date startTime, Date endTime);

	/**
	 * 根据工单id集合获取所有计划及实际执行人信息
	 * @param planIds
	 * @return
	 */
	List<PlanUserAllDTO> selectPlanUserAll(List<Long> planIds);

    List<UserPerformanceMonthPlanListDTO> listUserPerformancePlanList(@Param("lastMonth") String lastMonth,@Param("tenantId") String tenantId);

	List<FeiShuUserDeptElevatorWxPlanDTO> selectUserDeptElevatorWxPlan(@Param("lastMonth") String lastMonth,@Param("userIds") List<Long> userIds);

	List<ElevatorMaintainCostPlanListDTO> selectElevatorMaintainCostPlanListMonth(@Param("tenantId") String tenantId, @Param("lastMonth") String lastMonth,@Param("elevatorIds") List<Long> elevatorIds);

    List<BILarkRescueCountSourceVO> getGalaxyRescueResource(Date startDate, Date endDate);


    List<BiWxPlanListDTO> selectBIWxPlanList(@Param("startDate") Date startDate,@Param("endDate") Date endDate);

	List<ElevatorSimpleInfoVO> selectElevatorStopByPlan(@Param("planIds") List<Long> planIds);

	List<BiWxPlanListDTO> selectBiWxPlanUserList(@Param("planIds") List<Long> planIds);

	List<BiWxPlanListDTO> selectElevatorDeptPlan(@Param("startDate") Date startDate,@Param("endDate") Date endDate);

	List<BiWxPlanListDTO> selectElevatorUserPlan(@Param("startDate") Date startDate,@Param("endDate") Date endDate);

	List<ElevatorPlanUserDTO> selectCountByPlanUserSignature(@Param("tenantId") String tenantId);

	List<ElevatorPlanUserDTO> selectCountUserByPlanOverdue(@Param("tenantId") String tenantId);

    List<BiWxPlanListDTO> selectWxFaultPlanList(@Param("startDate") Date startDate,@Param("endDate") Date endDate);

	List<BiWxPlanListDTO> selectWxFaultPlanListAll(@Param("startDate") Date startDate,@Param("endDate") Date endDate);


	/**
	 * 根据电梯id获取工单
	 * @param eleId 电梯id
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @return 工单列表
	 */
    List<MaintainPlanContent> getPlanListOfElevatorId(@Param("eleId") Long eleId, @Param("beginTime")  Date beginTime,@Param("endTime")  Date endTime);


	String selectNextByDate(@Param("planId") Long planId);


    List<VerifyModifyPlanUserResultVO> selectVerifyModifyPlanUser(@Param("userDTO") BatchModifyPlanUserDTO userDTO);

	@InterceptorIgnore(tenantLine = "on")
	List<PlanListVo> selectByPlanListDown(IPage<PlanListVo> iPage,@Param("planSearchDTO") PlanSearchDTO planSearchDTO);

	List<Long> selectElevatorByCollectPlanIds(@Param("searchDTO") SugarSearchDTO searchDTO);

	List<ElevatorByCollectListDTO> selectElevatorByCollectList(@Param("planIds") List<Long> planIds);

	List<ElevatorByCollectListDTO> selectElevatorByCollectCorrelationZgList(@Param("planIds") List<Long> planIds);

	List<ElevatorByCollectListDTO> selectElevatorByCollectCorrelationZgStatusList(@Param("searchDTO") SugarSearchDTO searchDTO);
}
